package com.ids;

import com.google.common.base.Joiner;
import com.ids.redis.ListAd;
import org.rapidoid.config.Conf;
import org.rapidoid.http.Req;
import org.rapidoid.http.fast.On;
import org.rapidoid.http.fast.ReqHandler;

/**
 * Hello world!
 *
 */
public class App {

//    private String testString = "http://192.168.1.166:9999/ids/listAdsOfBeaconsMem.action?endUserSn=06E8F42D-6D92-4F1B-8519-1390FFE228F5&appToken=88B06E1BCBC69CF46AF11A91C8BF508E&triggerType=1&jsonBeacons=W3sibWFqb3IiOjEyMDAzLCJtaW5vciI6NDI0MDksInByb3hpbWl0eVV1aWQiOiJhM2ZjZTQzOC02MjdjLTQyYjctYWI3Mi1kYzZlNTVlMTM3YWMiLCJyc3NpIjotODF9LHsibWFqb3IiOjEwMTA0LCJtaW5vciI6NTAxNzcsInByb3hpbWl0eVV1aWQiOiJhM2ZjZTQzOC02MjdjLTQyYjctYWI3Mi1kYzZlNTVlMTM3YWMiLCJyc3NpIjotOTB9LHsibWFqb3IiOjE0ODUsIm1pbm9yIjozMzAxOCwicHJveGltaXR5VXVpZCI6ImEzZmNlNDM4LTYyN2MtNDJiNy1hYjcyLWRjNmU1NWUxMzdhYyIsInJzc2kiOi03N30seyJtYWpvciI6MTA4MDEsIm1pbm9yIjoxNTE4OCwicHJveGltaXR5VXVpZCI6ImEzZmNlNDM4LTYyN2MtNDJiNy1hYjcyLWRjNmU1NWUxMzdhYyIsInJzc2kiOi03MX0seyJtYWpvciI6MTQ4NSwibWlub3IiOjM0OTY0LCJwcm94aW1pdHlVdWlkIjoiYTNmY2U0MzgtNjI3Yy00MmI3LWFiNzItZGM2ZTU1ZTEzN2FjIiwicnNzaSI6LTY3fSx7Im1ham9yIjoxMDEwMSwibWlub3IiOjQ3MDkyLCJwcm94aW1pdHlVdWlkIjoiYTNmY2U0MzgtNjI3Yy00MmI3LWFiNzItZGM2ZTU1ZTEzN2FjIiwicnNzaSI6LTgxfSx7Im1ham9yIjoxNDg1LCJtaW5vciI6MzYwNzYsInByb3hpbWl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g4fSx7Im1ham9yIjoxNDg1LCJtaW5vciI6MzQ1ODQsInByb3hpbWl0eVV1aWQiOiJhM2ZjZTQzOC02MjdjLTQyYjctYWI3Mi1kYzZlNTVlMTM3YWMiLCJyc3NpIjotODF9LHsibWFqb3IiOjE0ODUsIm1pbm9yIjoyODkzOSwicHJveGltaXR5VXVpZCI6ImEzZmNlNDM4LTYyN2MtNDJiNy1hYjcyLWRjNmU1NWUxMzdhYyIsInJzc2kiOi04Nn0seyJtYWpvciI6MTAxMDEsIm1pbm9yIjo0NzgxMiwicHJveGltaXR5VXVpZCI6ImEzZmNlNDM4LTYyN2MtNDJiNy1hYjcyLWRjNmU1NWUxMzdhYyIsInJzc2kiOi03OX1d";

    public static void main( String[] args ) {

        runRapidoid(args);
    }

    public static void runRapidoid(String[] args) {
        Conf.args(args);

        On.address("0.0.0.0").port(9999);

        On.page("/ids/testConn.action").gui("Hello World!");

        On.get("/ids/listAdsOfBeaconsMem.action").json(new Handler());
    }
}

class Handler implements ReqHandler {

    @Override
    public Object handle(Req req) throws Exception {
        return "[" + Joiner.on(",").join(ListAd.getAdString(
                (String) req.data("endUserSn"),
                Integer.parseInt((String) req.data("triggerType")),
                (String) req.data("appToken"),
                (String) req.data("jsonBeacons")
        )) + "]";
    }
}